﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using zhangmenren.Db;
using zhangmenren.Models;

namespace zhangmenren.Repository
{
    public class AdminRepository:BaseRepository
    {
        /// <summary>
        /// 这里执行数据库内容
        /// </summary>
        public int Add(AdminEntity admin)
        {
            string sql = @"INSERT INTO Admin 
                            (UserName
                            ,Pwd
                            ,CreatorDT)
                        VALUES
                            (@UserName
                            ,@Pwd
                            ,GETDATE())";
            return Execute(connection => connection.Execute(sql, admin));
        }

        public IEnumerable<AdminEntity> GetAdmin(AdminEntity admin)
        {
            string sql = @"SELECT Id,UserName FROM Admin WHERE UserName=@UserName AND Pwd=@Pwd";
            return Execute(connection => connection.Query<AdminEntity>(sql, admin));
        }


        public void Adds<T>()
        {
            ExecuteTransaction((connection, transaction) =>
            {
                connection.Execute("", "", transaction: transaction);
                connection.Execute("", "", transaction: transaction);
            });
        }
    }
}
